/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model.estrutura;

import java.io.Serializable;
import java.util.ArrayList;

/**
 *
 * @author Thiago
 */
public class Ponto implements Serializable {

    private double x, y, z;       //coordenadas de mundo
    private double nx, ny, nz;    //vetor normal do mundo
    private ArrayList<Face> faces;

    public Ponto(double x, double y, double z) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.faces = new ArrayList<>();
    }

    public Ponto getNormal() {
        //Calcula a normal
        double temp = (x * x) + (y * y) + (z * z);
        temp = Math.sqrt(temp);
        this.nx = this.x / temp;
        this.ny = this.y / temp;
        this.nz = this.z / temp;
        return new Ponto(this.nx, this.ny, this.nz);
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public double getZ() {
        return z;
    }

    public void setZ(double z) {
        this.z = z;
    }

    public boolean equals(Ponto p) {
        if (this.x == p.getX() && this.y == p.getY() && this.z == p.getZ()) {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return new String(x + " \t" + y + " \t" + z).replace(".", ",");
    }

    public void setPonto(Ponto p) {
        this.x = p.x;
        this.y = p.y;
        this.z = p.z;
        this.nx = p.nx;
        this.ny = p.ny;
        this.nz = p.nz;
    }
    
    public void addFace(Face f){
        this.faces.add(f);
    }
    
    public ArrayList<Face> getFaces(){
        return this.faces;
    }
}
